// shopowner/pages/designchart/designchart.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    explain: "",
    depositprictrueList: []
  },
  // 上传铺贴图
  bindUnplone() {
    let t = this
    wx.chooseMedia({
      count: 9 - t.data.depositprictrueList.length,
      mediaType: ['image'],
      maxDuration: 60,
      success(res) {
        let depositprictrueList = t.data.depositprictrueList

        res.tempFiles.forEach(item => depositprictrueList.push(item.tempFilePath))
        t.setData({
          depositprictrueList: depositprictrueList
        })

      }
    })
  },
  // 预览铺贴图
  previewImage(e) {
    let depositprictrueList = this.data.depositprictrueList
    let url = e.currentTarget.dataset.url
    wx.previewImage({
      current: url, // 当前显示图片的 http 链接
      urls: depositprictrueList, // 需要预览的图片 http 链接列表
      success() {

      }
    })
  },
  // 删除铺贴图
  del(e) {
    let depositprictrueList = this.data.depositprictrueList
    depositprictrueList.splice(e.currentTarget.dataset.index, 1)
    this.setData({
      depositprictrueList: depositprictrueList
    })
  },
  tab() {
    if (this.data.depositprictrueList.length == 0) {
      wx.showToast({
        title: '请上传铺贴图',
        duration: 2500, //持续的时间
        icon: 'none', //图标
      })
      return
    }

    if (this.data.todo == 'modify') {
      let pages = getCurrentPages();
      let prevPage = pages[pages.length - 2]; //prevPage 是获取上一个页面的js里面的pages的所有信息。 -2 是上一个页面，-3是上上个页面以此类推。\\
      prevPage.setData({
        depositprictrueList: this.data.depositprictrueList,
        explain: this.data.explain,
      })
      wx.navigateBack({
        delta: 1,
      })

    } else {

      wx.navigateTo({
        url: '/shopowner/pages/ProductDrawing/ProductDrawing?product=' + JSON.stringify(this.data.product) + "&&explain=" + this.data.explain + "&&depositprictrueList=" + JSON.stringify(this.data.depositprictrueList) + "&&id=" + this.data.id,
      })
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    console.log(options)

    if (options.todo) {
      console.log(options)
      this.setData({
        todo: options.todo,
        explain: options.explain,
        depositprictrueList: JSON.parse(options.depositprictrueList)
      })
    } else {
      this.setData({
        product: JSON.parse(options.product),
        id: options.id
      })
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})